*-------------------------------------------------------------------------------------------------------------*
* The Causal Effects of R&D Grants: Evidence from a Regression Discontinuity (Santoleri et al., 2020)
*-------------------------------------------------------------------------------------------------------------*

/// Table 1: Descriptive statistics on SME Instrument competitions and applicants 

use $data_path/DATA_ALL_FINAL.dta, clear 

* Panel A: competitions (raw data)
**********************************************************
preserve
collapse (first) phase_smei  (count) firm_id (sum) n_award=award , by(competition)

label var competition "# competitions"
label var firm_id "# applicants per competition"
label var n_award "# winning applicants per competition"

eststo clear
eststo: estpost summ competition firm_id  n_award  if phase_smei==2, det
esttab est* using $output/Table_1.txt, replace cells("mean(fmt(2) label(Mean)) sd(fmt(2) label(SD))  p50(fmt(0) label(Median)) count(fmt(0) label(N)) sum(fmt(0) label(N))" ) label nomtitle noobs  varwidth(40) title(Table 1: Descriptive statistics on SME Instrument competitions and applicants)
esttab est* using $output/Table_1.tex, replace cells("mean(fmt(2) label(Mean)) sd(fmt(2) label(SD))  p50(fmt(0) label(Median)) count(fmt(0) label(N)) sum(fmt(0) label(N))" ) label nomtitle noobs  varwidth(40) title(Table 1: Descriptive statistics on SME Instrument competitions and applicants)
restore

* Panel B: competitions (cleaned data)
**********************************************************
preserve
drop if d_patents_pre==. & d_patents_post==. /*  matched==0 */ 
collapse (first) phase_smei  (count) firm_id  (sum) n_award=award , by(competition)  

label var competition "# competitions"
label var firm_id "# applicants per competition"
label var n_award "# winning applicants per competition"

eststo clear
eststo: estpost summ competition firm_id  n_award if phase_smei==2, det
esttab est* using $output/Table_1.txt, append cells("mean(fmt(2) label(Mean)) sd(fmt(2) label(SD))  p50(fmt(0) label(Median))  count(fmt(0) label(N)) sum(fmt(0) label(N))" ) label nomtitle noobs  varwidth(40) nonum
esttab est* using $output/Table_1.tex, append cells("mean(fmt(2) label(Mean)) sd(fmt(2) label(SD))  p50(fmt(0) label(Median))  count(fmt(0) label(N)) sum(fmt(0) label(N))" ) label nomtitle noobs  varwidth(40) nonum
restore

* Panel C: applicants (cleaned data)
**********************************************************
preserve
replace ln_citw_patents_pre = . if ln_citw_patents_post==.
replace ln_citw_patents_post = . if ln_citw_patents_pre==.
replace d_patents_pre = . if d_patents_post==.
replace d_patents_post = . if d_patents_pre==.

* list of covariates
global covbal n_patent_pre_w  citw_patents_pre_w pe_amount_tm1  pe_pre  opturnover_tm1  numberofemployees_tm1  totalassets_tm1  age_pre high_tech   exit3 

label var firm_id "# applicants"

label var citw_patents_post_w "Citw patents$^{Post}$"
label var citw_patents_pre_w "Citw patents$^{Pre}$"
label var n_patent_post_w "Patents$^{Post}$"
label var n_patent_pre_w "Patents$^{Pre}$"
label var pe_amount_tm1 "Private Equity$^{Pre}$ (1,000 \euro)"
label var pe_post "Private Equity$^{Post}$ (d)"
label var pe_pre "Private Equity$^{Pre}$ (d)"
label var opturnover_tp1 "Revenues$^{Post}$ (1,000 \euro)"
label var opturnover_tm1 "Revenues$^{Pre}$ (1,000 \euro)"
label var totalassets_tp1 "Assets$^{Post}$ (1,000 \euro)"
label var totalassets_tm1 "Assets$^{Pre}$ (1,000 \euro)"
label var numberofemployees_tp1 "Employees$^{Post}$"
label var numberofemployees_tm1 "Employees$^{Pre}$"
label var age_pre "Age$^{Pre}$"
label var high_tech "High-Tech (d)"
label var exit3 "Failure (d)"
*label var ipo_post "IPO (d)"

eststo clear
eststo: estpost summ $covbal if phase_smei==2, det
esttab est* using $output/Table_1.txt, append   cells("mean(fmt(2) label(Mean)) sd(fmt(2) label(SD))  p50(fmt(0) label(Median))  count(fmt(0) label(N)) " ) label nomtitle noobs  varwidth(40)  nolegend  nonumbers 
esttab est* using $output/Table_1.tex, append   cells("mean(fmt(2) label(Mean)) sd(fmt(2) label(SD))  p50(fmt(0) label(Median))  count(fmt(0) label(N)) " ) label nomtitle noobs  varwidth(40)  nolegend  nonumbers 






